package com.felix.thread.philosopher;

/**
 * Philosopher
 *
 * @author xuejinhua
 * @date 2018/10/8 17:29
 */
public class Philosopher implements Runnable {

    private int bites = 10;

    private Chopstick left, right;

    private String name;

    public Philosopher(Chopstick left, Chopstick right, String name) {
        this.left = left;
        this.right = right;
        this.name = name;
    }

    public void eat() {
        System.out.println(name + "饥饿");
        pickUp();
        chew();
        putDown();
    }

    private void pickUp() {
        left.pickUp();
        right.pickUp();
    }

    public void chew() {
    }

    public void putDown() {
        left.putDown();
        right.putDown();
    }

    @Override
    public void run() {
        for (int i = 0; i < bites; i++) {
            eat();
        }
    }
}
